package com.xmmj.baselibrary.utils.adapter.viewpager

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter

class ViewPagerAdapter2(
    fragmentActivity: FragmentActivity,
    private val mFragments: List<Fragment>
) :
    FragmentStateAdapter(fragmentActivity) {

    override fun createFragment(position: Int): Fragment {
        if (mFragments.isEmpty()) {
            return null!!
        }
        return if (position < mFragments.size) mFragments[position] else null!!
    }

    override fun getItemCount(): Int {
        return mFragments.size
    }
}